package source;

import java.util.Vector;

public class Construction {
	private final String name;
	private final int playerID;

	//vector cu hashCode-urile dronelor ce participa la aceasta constructie
	private final Vector<Integer> hashCodeVector = new Vector<Integer>();
	
	//viata maxima
	private final int maxLife;
	
	//viata curenta
	private int life;
	
	//pasul cu care se creste viata, functie de cate drone participa la constructie
	private int lifeCounter;

	//obiect lacat pe viata curenta a constructiei 
	private Object lifeLock = new Object();

	public Construction(String name, int maxLife, int playerID, int hashCode) {
		this.life = 0;
		this.lifeCounter = 5;
		this.name = name;
		this.maxLife = maxLife;
		this.playerID = playerID;
		this.hashCodeVector.add(hashCode);
	}

	//verificare a cui e constructia
	public boolean hasOwner(int playerID) {
		return playerID == this.playerID;
	}

	//verificare daca e terminata constructia
	public boolean isBuilt() {
		synchronized (lifeLock) {
			return life >= maxLife;
		}
	}

	//metoda de construire efectiva
	public void build(int hashCode) {
		synchronized (lifeLock) {
			if (!hashCodeVector.contains(hashCode)) {
				lifeCounter += 5;
				hashCodeVector.add(hashCode);
			}
			life += lifeCounter;
		}
	}

	
	//returneaza punctajul acestei constructii in functie de tipul sau, casa sau statuie
	public int getPoints() {
		if (name.equals("House"))
			return 5;

		return 20;
	}
}
